package treazy.ultimate.stats;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

public class NewPlayerActivity extends Activity {
	private Button create;
	private String teamName;
	private Button cancel;
	
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		
		setContentView(R.layout.newplayer);
		
		create = (Button) findViewById(R.id.createPlayerButton);
		
		final Bundle extras = getIntent().getExtras();
	    if (extras != null) 
	    	teamName = extras.getString("TeamName");
		
		create.setOnClickListener(new View.OnClickListener() {
			public void onClick(View v){
				EditText playerName = (EditText) findViewById(R.id.playerName);
				
				DatabaseHandler db = new DatabaseHandler(NewPlayerActivity.this);
		        db.addPlayer(new Player(playerName.getText().toString(), teamName));
				
				Intent i = new Intent(getApplicationContext(), ViewRosterActivity.class);
				i.putExtra("TeamName", teamName);
				startActivity(i);
				
			}
		});
		
		cancel = (Button) findViewById(R.id.cancelnewplayer);
		
		cancel.setOnClickListener(new View.OnClickListener() {
			public void onClick(View v){
				Intent i = new Intent(getApplicationContext(), ViewRosterActivity.class);
				startActivity(i);
				
			}
		});

	}
}
